package com.vanke.kotlin.data.server

import com.google.gson.Gson

/**
 * @name Kotlin
 * @package name：com.vanke.kotlin
 * @class describe
 * @anthor shiyuchuan
 * @time 2017/7/20 17:19
 */
public class ForecastRequest(val zipcode: Long ){
    companion object {
        private val APP_ID = "d639f911bc7aa3a318cd9ed6aac4e1b2"
        private val URL = "http://api.openweathermap.org/data/2.5/" +
                "forecast/daily?&mode=json&units=metric&cnt=7"
        private val COMPLETE_URL = "${URL}&appid=${APP_ID}&q="
    }
    fun execute(): ForecastResult {
        val forecastJsonStr = java.net.URL(COMPLETE_URL +zipcode).readText()
        return Gson().fromJson(forecastJsonStr, ForecastResult::class.java)
    }
}